<script setup>
import router from "@/router";
import { onMounted, onUnmounted, ref } from "vue";
import useHomeStroe from "@/stores/home";
import { storeToRefs } from "pinia";
import searchBox from "./cpns/searchBox.vue";
import categories from "./cpns/categories.vue";

const inputVal = ref();
const clickAddress = () => {
  router.push("./city");
};
function test() {
  const scrollTop = ref(0);
  scrollTop.value = document.documentElement.scrollTop;
  console.log(scrollTop.value, "scrollTop");
}
// 请求数据
const homeStore = useHomeStroe();
homeStore.fetchDatas();
homeStore.fetchCategories();
const hotChoose = ref();
// 监听滚动
onMounted(() => {
  console.log(hotChoose, hotChoose.value.scrollTop, "hotChoose.$el.");
  window.addEventListener("scroll", test);
});
onUnmounted(() => {
  window.removeEventListener("scroll", test);
});
</script>

<template>
  <div class="home">
    <div class="title">泓源旅途</div>
    <div class="img">
      <img src="@/assets/img/home/banner.webp" alt="">
    </div>
    <div class="address">
      <div class="city" @click="clickAddress">广州</div>
      <div class="mylocation">
        <span>我的位置</span>
        <img src="@/assets/img/home/icon_location.png" alt="">
      </div>
    </div>
    <!--  搜索区域  -->
    <searchBox></searchBox>
    <!-- 分类区域 -->
    <categories></categories>
    <div class="hotChoiceness">
      <h2 name='hhh' ref="hotChoose">热门精选</h2>
      <div class="hc-v9">
        <img src="@/assets/img/home/loading-bg.png" alt="">
        <div class="text">
          sss
        </div>
      </div>
      <div class="hc-v3"></div>
    </div>
  </div>
</template>
<style lang="less">
.home {
  overflow-x: hidden;
  .title {
    font-size: 18px;
    color: var(--primary-color);
    height: 44px;
    line-height: 44px;
    text-align: center;
  }
  .img {
    img {
      width: 100%;
    }
  }
  .address {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 20px;
    .city {
      flex: 1;
    }
    .mylocation {
      width: 80px;
      display: flex;
      img {
        width: 20px;
        position: relative;
        top: -2px;
        margin-left: 3px;
      }
    }
  }
}
.hotChoiceness {
  margin: 20px 20px 10px 20px;
  width: 50%;
  .hc-v9 {
    position: relative;
    img {
      width: 100%;
      border: 1px solid;
    }
    .text {
      position: absolute;
      bottom: 0;
    }
  }
}
</style>

